import ParseBasicConfig

########################################################################
class ParseUSBConfig(ParseBasicConfig.ParseBasicConfig):
    """Parse config files against USB specific values. Inherits from 
    ParseBasicConfig."""

    #----------------------------------------------------------------------
    def __init__(self, file, section):
        """Constructor. Set up config params in config file (or creates new one)."""
        #super reads config or creates it and basic options within
        super(ParseUSBConfig, self).__init__(file, section)
        
        config = self.config
        
        if not config.has_option(section, 'usb.vendor'):
            config.set(section, 'usb.vendor', '')
        self.usbVendor = config.get(section, 'usb.vendor')
        
        if not config.has_option(section, 'usb.product'):
            config.set(section, 'usb.product', '')
        self.usbProduct = config.get(section, 'usb.product')        
        
        if not config.has_option(section, 'usb.serial'):
            config.set(section, 'usb.serial', '')
        self.usbSerial = config.get(section, 'usb.serial')        

        if not config.has_option(section, 'usb.udev_rule_path'):
            config.set(section, 'usb.udev_rule_path', '')
        self.usbUdevRulePath = config.get(section, 'usb.udev_rule_path')        

        if not config.has_option(section, 'usb.min_period'):
            config.set(section, 'usb.min_period', '1')
        self.usbMinPeriod = config.get(section, 'usb.min_period')        
        
        self.saveChanges()
        
    #----------------------------------------------------------------------
    # getters
    #----------------------------------------------------------------------
    def getUSBVendor(self):
        """Returns USB Vendor 4 bytes hex code"""
        return self.usbVendor   
    
    #----------------------------------------------------------------------
    def getUSBProduct(self):
        """Returns USB Product 4 bytes hex code"""
        return self.usbProduct   
    
    #----------------------------------------------------------------------
    def getUSBSerial(self):
        """Returns USB device serial number"""
        return self.usbSerial
    
    #----------------------------------------------------------------------
    def getUSBUdevRulePath(self):
        """Returns USB udev rule path"""
        return self.usbUdevRulePath   
    
    #----------------------------------------------------------------------
    def getUSBMinPeriod(self):
        """Returns minimal period between backups"""
        return self.usbMinPeriod   
        
        
    #----------------------------------------------------------------------
    # saver inherited
    #----------------------------------------------------------------------
    
    #----------------------------------------------------------------------
    # setters
    #----------------------------------------------------------------------
    def setUSBVendor(self, vendor):
        """Sets USB Vendor 4 bytes hex code"""
        self.usbVendor = vendor
        self.config.set(self.section, "usb.vendor", vendor)
    
    #----------------------------------------------------------------------
    def setUSBProduct(self, product):
        """Sets USB Product 4 bytes hex code"""
        self.usbProduct = product
        self.config.set(self.section, "usb.product", product)
        
    #----------------------------------------------------------------------
    def setUSBSerial(self, serial):
        """Sets USB device serial number"""
        self.usbSerial = serial
        self.config.set(self.section, "usb.serial", serial)
        
    #----------------------------------------------------------------------
    def setUSBUdevRulePath(self, udevRulePath):
        """Sets USB udev rule path"""
        self.usbUdevRulePath = udevRulePath
        self.config.set(self.section, "usb.udev_rule_path", udevRulePath)
    
    #----------------------------------------------------------------------
    def setUSBMinPeriod(self, period):
        """Sets USB minimal period between backups"""
        self.usbMinPeriod = period
        self.config.set(self.section, "usb.min_period", period)